function searchBook() {
    if(window.location.href.indexOf("index1")==-1){
        return void(0);
    }

    var receivedata=getParams("index1");
    var  str = receivedata.split("!");

    $.ajax({
        //几个参数需要注意一下
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型'
        headers : {authorization:header},
        url: "http://120.79.183.142/api/manageBooks/searchBooks" ,//url
        data: { "name":str[1],
            "author":str[2],
            "publisher":str[3]
        } ,

        success: function (receive_data) {
            if (receive_data["code"] == 200)
            {
                //在列表中打印结果
                var result = receive_data["data"];
                var num = result.length;
                for (var index2 = 0; index2 < num; index2++) {
                    var irow = result[index2];
                    var bid = irow['bid'];
                    var name = irow["name"];
                    var author = irow["author"];
                    var publisher = irow["publisher"];
                    var total_num = irow["total_num"];
                    var remain_num = irow["remain_num"];
                    var price = irow["price"];
                    var str = '<tr class="tr_' + index2 + '">' + '<td>' + bid + '</td> <td>' + name + '</td><td>' + author + '</td><td>' + publisher + '</td><td>'
                        + total_num + '</td> <td>' + remain_num + '</td> <td>' + price + '</td> ' + '<td><button class="btn btn-success btn-xs" data-toggle="modal" data-target="#reviseBook" onclick="borrow(this)">借阅</td></tr>';
                    $("#list_ma").append(str);
                }
            }

            else{
                $("#fail").css('opacity',100);
                setTimeout(function () {
                    $("#fail").css('opacity',0);
                },2500);
            }
            f2();
        },
        error : function(r) {
            console.log(r);
        }
    })
}

function getParams(key) {
    var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    //如果地址栏中出现中文则进行编码
    var r = encodeURI(window.location.search).substr(1).match(reg);
    if (r != null) {
        //将中文编码的字符重新变成中文
        return decodeURI(unescape(r[2]));
    }

}

function borrow(bid)
{

    borrowbid = bid.parentNode.parentNode.children[0].innerHTML;
    $.ajax({
        url:"http://120.79.183.142/api/book/borrow",
        headers : {authorization:header},
        type:"post",
        dataType:"json",
        data:{"bid":borrowbid},
        success : function(result) {
            console.log(result["code"]);
            if (result["code"] == 200 )
            {
                bid.parentNode.parentNode.children[5].innerHTML = parseInt(bid.parentNode.parentNode.children[5].innerHTML) - 1;
                $("#success").css('opacity',100);
                setTimeout(function () {
                    $("#success").css('opacity',0);
                },2500);
            }
            else
            {
                $("#fail").css('opacity',100);
                setTimeout(function () {
                    $("#fail").css('opacity',0);
                },2500);
            }

        }

    })
}


function f2(){
    $("#list_ma").DataTable({
        destroy:true,
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        }
    });
}
